<?php
	echo $this->Html->css(array('jquery.ui.button','jquery.ui.position','jquery.ui.autocomplete'));
	echo $this->Html->script(array('jquery.ui.button','jquery.ui.position','jquery.ui.autocomplete','autocombo')); 
?>
<style>
	.ui-autocomplete {
		max-height: 100px;
		overflow-y: auto;
		/* prevent horizontal scrollbar */
		overflow-x: hidden;
		/* add padding to account for vertical scrollbar */
		padding-right: 20px;
	}
	/* IE 6 doesn't support max-height
	 * we use height instead, but this forces the menu to always be this tall
	 */
	* html .ui-autocomplete {
		height: 100px;
	}
	</style>
<script>
	$(function() {
		$("#docgia").combobox();
		$('#phat').hide();
		$("#btsubmit").live("click", function (event){
										if(validate())
										{
											$('#lbdgia').hide();
											$.ajax({data:$("#btsubmit").closest("form").serialize(),
											dataType:"html",
											success:function (data, textStatus) {$("#sachdangmuon").html(data);},
											type:"post",
											url:$('#root').val()});
											return false;
										}
										else
										{
											return false;
										}
									});
		$(".checkall").live("click", function (event){
					if($(this).prop('checked')==true)
						$('.check').prop('checked',true); 
					else 
						$('.check').prop('checked',false);
					});
	
		$('#cbphat').click(function(){if($(this).prop('checked')==true)$('#phat').show(); else $('#phat').hide();});
	});

function validate()
{
	if($('#docgia').val()=='')
	{
		alert('Bạn chọn độc giả');
		return false;
	}
	checked = 0;
	$('input:checkbox').each(function(){
										if($(this).prop('class')=='check' && $(this).prop('checked')==true)
										{
											
											checked += 1; 
										}
									});
	if(checked ==0)
	{
		alert('Bạn chọn sách trả');
		return false;
	}
	if($('#cbphat').prop('checked')==true)
	{
		if($('#htp').val()=='')
		{
			alert('Bạn chọn hình thưc phạt');
			return false;
		}
		/*
		 if($('#mp').val()=='')
		 		{
		 			alert('B?n nh?p m?c ph?t');
		 			$('#mp').focus();
		 			return false;
		 		}
		 */
		
	}
	return true;
}
</script>
<div id="tabs">
	<ul>
        <li><?php echo $this->Html->link(__('Mượn sách', true), array('controller'=>'giaodichmuontras','action' => 'muonsach')); ?></li>
        <li id="current"><?php echo $this->Html->link(__('Trả sách', true), array('controller'=>'giaodichmuontras','action' => 'trasach')); ?></li>
        <li><?php echo $this->Html->link(__('Gia hạn', true), array('controller'=>'giaodichmuontras','action' => 'giahan_tt')); ?></li>
        
	</ul>
 </div>
<div class="index">
<fieldset>
<legend>Trả sách</legend>
<?php echo $form->input('',array('id'=>'root','label'=>false,'type'=>'hidden','value'=>$this->webroot.'giaodichmuontras/luutrasach'));?>
<?php echo $form->create('Giaodichmuontra',array('id'=>'frmgd'));?>
<?php echo $form->input('docgia_id',array('id'=>'docgia','label'=>'Mã độc giả','type'=>'select','options'=>$docgias,'empty'=>''));?>
<?php echo $form->checkbox('phat',array('id'=>'cbphat'));?> Phạt
<div id='phat'>
<?php echo $form->input('htxp',array('id'=>'htp','label'=>'Hình thức phạt','options'=>$htviphams,'type'=>'select','empty'=>'--Chọn hình thức phạt--')); ?>
<?php echo $form->input('mucphat',array('id'=>'mp','label'=>'Mức phạt (VNĐ)','type'=>'text'));?>
<?php echo $form->input('ghichu',array('id'=>'ghichu','label'=>'Ghi chú','type'=>'textarea'));?>
</div>
<div id='ttdocgia'></div>
<div id='sachdangmuon'></div>
<div class="submit"><input id="btsubmit" type="submit" value=" Lưu " /></div>
</fieldset>
<?php $this->Js->get('#docgia')->event('change',
							$this->Js->request(array('controller' => 'giaodichmuontras', 'action' => 'layttdocgia'),
							array('update' => '#ttdocgia','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));?>
<?php $this->Js->get('#docgia')->event('change',
							$this->Js->request(array('controller' => 'giaodichmuontras', 'action' => 'laysachdangmuontr'),
							array('update' => '#sachdangmuon','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));?>
</div>